package com.wanpinghui.supplier.message.nim;

import com.alibaba.fastjson.JSONObject;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;


/**
 * Created by xiongning on 17-12-5.
 */

public abstract class WPHAttachment implements MsgAttachment {


    public static final int TYPE_NEW_ORDER = 10;

    public static final int TYPE_CHAT = 20;//聊天类型是普通聊天

    public static final int TYPE_ORDER_SUCCESS = 30;

    public static final int TYPE_SERVICE = 40;//聊天类型是和客服聊天

    protected int msg_type;//聊天类型

    public int getMsg_type() {
        return msg_type;
    }

    public void setMsg_type(int msg_type) {
        this.msg_type = msg_type;
    }

    public WPHAttachment(int msg_type) {
        this.msg_type = msg_type;
    }

    // 解析附件内容。
    public void fromJson(JSONObject data) {
        if (data != null) {
            parseData(data);
        }
    }

    // 实现 MsgAttachment 的接口，封装公用字段，然后调用子类的封装函数。
    @Override
    public String toJson(boolean send) {
        return WPHAttachParser.packData(msg_type, packData());
    }

    // 子类的解析和封装接口。
    protected abstract void parseData(JSONObject data);

    protected abstract JSONObject packData();
}
